<template>
  <div>
    <el-upload :action="action" list-type="picture-card" :auto-upload="autoUpload" :on-success="upSuccess" :file-list="productFileList" :on-preview="handlePictureCardPreview">
      <!-- <i slot="default" class="el-icon-plus"></i>
      <div slot="file" slot-scope="{ file }">
        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
        <span class="el-upload-list__item-actions">
          <span
            class="el-upload-list__item-preview"
            @click="handlePictureCardPreview(file)"
          >
            <i class="el-icon-zoom-in"></i>
          </span>
          <span
            v-if="!disabled"
            class="el-upload-list__item-delete"
            @click="handleDownload(file)"
          >
            <i class="el-icon-download"></i>
          </span>
          <span
            v-if="!disabled"
            class="el-upload-list__item-delete"
            @click="handleRemove(file)"
          >
            <i class="el-icon-delete"></i>
          </span>
        </span>
      </div> -->
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="" />
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "uploadCommon",
  props: {
    action: String,
    autoUpload: Boolean,
    productFileList: Array
  },
  data() {
    return {
      productFiles: [...this.productFileList],
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false
    };
  },
  created(){
    console.log("log1",this.productFileList);
    console.log(this.action);
  },
  methods: {
    handleRemove(file) {
      console.log(file);
    },
    handlePictureCardPreview(file) {
        console.log("log",this.flieUrls);
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
      console.log("this.dialogImageUrl",this.dialogImageUrl);
    },
    upSuccess(res, file){
        this.productFiles.push({name:file.name,url:res})
        console.log(res,file)
        this.$emit("flieUrl",productFiles)
        // this.flieUrl(res);
    },
    handleDownload(file) {
      console.log(file);
    }
  }
};
</script>
